﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Avatar.Common;
using AvatarHelper;
using Avatar.Model;

public partial class NewsView : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            var _id = Request.QueryString["ID"] != null ? Request.QueryString["ID"].ToString() : string.Empty;
            if (string.IsNullOrEmpty(_id))
            {
                Helper.ShowMassage("您查看的文章不存在。", "./news.aspx");
            }
            else
            {
                using (var _adc = DBHelper.GetDataContext())
                {
                    var _news = _adc.News.FirstOrDefault(n => n.ID == new Guid(_id));
                    if (_news == null) Helper.ShowMassage("您查看的文章不存在。", "./news.aspx");

                    _news.Hits++;
                    Page.Title = _news.Title;
                    lbl_Title.Text = _news.Title;
                    lbl_PublishDate.Text = _news.PublishDate.ToShortDateString();
                    lbl_Hits.Text = _news.Hits.ToString();
                    lbl_Content.Text = _news.Content;

                    _adc.SubmitChanges();
                }
            }
        }
    }
}
